package com.boost.handler;

import com.boost.ecoder.HexDecoder;
import com.boost.ecoder.HexEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.timeout.IdleStateHandler;
import sun.reflect.CallerSensitive;

import java.util.concurrent.TimeUnit;

/**
 * @author Santa
 * @since 2020/3/19
 */

public class NettyChildHandler extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        //获取管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        //然后向管道添加
        pipeline.addLast("decoder",new HexDecoder());
        pipeline.addLast("encoder",new HexEncoder());
        //加入心跳检测
        pipeline.addLast(new IdleStateHandler(70,70,70, TimeUnit.SECONDS));
        //加入业务处理的handler
        pipeline.addLast(new BizHandler());
    }
}























